home *** CD-ROM | disk | FTP | other *** search
/ MacWorld 1995 November / Macworld Nov ’95.toast / Developers / Selection ƒ 2.5 / font < prev    next >
Encoding:
Text File  |  1994-11-06  |  2.3 KB  |  122 lines  |  [TEXT/MSET]

  1.  \ 28Oct94 dbh updated to 2.5 syntax
  2.  
  3. (*
  4.  
  5. The concept behind the font class is to have a class that guarantees proper 
  6. handling of the basic font attributes on the Macintosh.  We make no 
  7. assumptions about the font number, but rather store the font name and then obtain 
  8. the font number via a toolbox call each time we run the program.
  9. We default to Monaco 9 plain text.  Important, we must *always* do a getnew:
  10. before using the font.  See class staticText for how to use.
  11.  
  12.  
  13. *)
  14.  
  15.  
  16.  
  17. \ these could be konst's to save a little dictionary space
  18. 0 constant plain
  19. 1 constant bold
  20. 2 constant italic
  21. 4 constant underline
  22. 8 constant outline
  23. 16 constant shadow
  24. 32 constant condensed
  25. 64 constant extended
  26.  
  27. :class font super{ object }
  28. \ must never set these directly
  29.     record FontInfo {
  30.     int ascent
  31.     int descent
  32.     int widMax
  33.     int leading
  34.     }
  35.     int lineheight    \ computed at getnew: time
  36.  
  37.     int font#
  38.  
  39. \ user settable
  40.     $16 name
  41.     int    fontsize
  42.     int mode
  43.     int style
  44.     
  45. :m classinit:
  46.     " Monaco" put: name
  47.     9 put: fontsize
  48.     konst srcOr put: mode
  49.     plain put: style
  50.     ;m
  51.  
  52. :m set:        \ must only do after a getnew:
  53.     get: font# tfont
  54.     get: fontsize  tsize
  55.     get: style tface
  56.     get: mode tmode ;m
  57.  
  58. :m getnew:
  59.     get: name str255  font#  call GetFNum \ 28Oct94 dbh
  60.     set: self
  61.     FontInfo call GetFontInfo \ 28Oct94 dbh
  62.     get: ascent
  63.     get: descent +
  64.     get: leading + put: lineheight
  65.     ;m
  66.  
  67. \ the following are only valid after a getnew:
  68. :m ascent:  ( -- n)
  69.     get: ascent ;m
  70.  
  71. :m descent:  ( -- n)
  72.     get: descent ;m
  73.  
  74. :m widMax:  ( -- n)
  75.     get: widMax ;m
  76.  
  77. :m leading:  ( -- n)
  78.     get: leading ;m
  79.  
  80. :m lineheight:  ( -- n)
  81.     get: lineheight ;m
  82.  
  83. (*  just for debugging
  84. :m dumpfont:
  85.     cr ." ascent " ascent: self initfont .
  86.     cr ." descent "  descent: self initfont .
  87.     cr ." widMax "   widMax: self initfont .
  88.     cr ." leading " leading: self initfont .
  89.     cr ." lineheight " lineheight: self initfont .
  90.     cr ." fontnumber " get: font# initfont .
  91.     cr ." fontname " initfont print: name
  92.     cr ." fontsize " get: fontsize initfont .
  93.     cr ." style " get: style initfont .
  94.     cr ." mode " get: mode initfont .
  95.     ;m
  96. *)
  97.  
  98. \ user settable, call anytime.  But won't take effect without
  99. \ a subsequent getnew:
  100. :m fontName:  ( addr len -- )
  101.     put: name ;m
  102.  
  103. :m fontSize:  ( n -- )
  104.     put: fontsize ;m
  105.  
  106. :m mode:  ( n -- )
  107.     put: mode ;m
  108.  
  109. :m style:  ( n -- )
  110.     put: style ;m
  111.  
  112. ;class
  113.  
  114. endload
  115.  
  116. *** EXAMPLE USE
  117.  
  118. See class staticText for how to use.
  119.  
  120.  
  121.  
  122.